package productions;

import exceptions.ParserException;
import lexico.ErrorTable;
import lexico.SymbolTable;
import lexico.TokenClass;

/**
 * @author heekinho
 */
public class ChamadaFuncaoProduction extends AbstractProductionRule {
    /* Muitos dos métodos irão precisar de algo assim: */

    private static ChamadaFuncaoProduction instance = new ChamadaFuncaoProduction();

    public static ChamadaFuncaoProduction getInstance() {
        return instance;
    }


    /**
     * Regra: chamada_funcao : '(' params? ')';
     * @return
     * @throws ParserException
     */
    @Override
    public boolean analyze(SymbolTable st, ErrorTable et) throws ParserException {
        if (!basicParse(st, TokenClass.DELIMITER_OPENING_PARENTHESIS)) {
            return false;
        }
        ParamsProduction.getInstance().analyze(st, et);
        if (!basicParse(st, TokenClass.DELIMITER_CLOSING_PARENTHESIS)) {
            return skipUntilSynchronize(st, et, "Era esperado um '('");
        }
        return true;
    }

    @Override
    protected void populateFirst() {
        first.add(TokenClass.DELIMITER_OPENING_PARENTHESIS);
    }

    @Override
    protected void populateFollow() {
        follow.addAll(SentencaProduction.getInstance().follow);
        follow.addAll(FatorProduction.getInstance().follow);
    }

}
